package com.tender.integration.config.resttemplate;

import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyRestTemplateInterceptor implements ClientHttpRequestInterceptor {

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body,
                                        ClientHttpRequestExecution execution) throws IOException {
        // 在这里可以修改请求头或打印请求信息
        System.out.println("Request URL: " + request.getURI());
        System.out.println("Request Method: " + request.getMethod());

        // 继续执行请求
        ClientHttpResponse response = execution.execute(request, body);

        // 在这里可以修改响应，或者记录响应信息
        System.out.println("Response Status Code: " + response.getStatusCode());

        return response;
    }
}